clear all
set printcolor gs1, permanently
set more off
global dirout ""
global dirgeolocalized ""

use client_uuid request_timestamp_local is_cash_trip original_fare_usd using "$dirgeolocalized/Datos Geolocalizados.dta", clear
gen date_temp=substr(request,1,10)
split date, p("-")
rename date_temp1 year
collapse (sum) original_fare_usd, by(is_cash_trip client_uuid year)
merge m:1 client_uuid using "$dirgeolocalized/users_geolocalized.dta", keepusing(ID) keep(match) nogenerate
rename ID_origin ID
merge m:1 ID using "$dircenso/censo_CDMX_geo.dta", keepusing(GRAPROES CVE_ENT POBTOT VPH_AUTOM VPH_CEL VPH_INTER VIVTOT ) keep(match) nogenerate
keep if CVE_ENT=="15"
gen cash=(is_cash_trip=="TRUE")
drop is_cash_trip
egen long user=group(client_uuid)
format user %15.0g
drop client CVE_ENT
destring year, replace


foreach var in VPH_AUTOM VPH_CEL VPH_INTER {
gen s`var'=`var'/VIVTOT
}

keep if VIVTOT>0
keep if POBTOT>0

keep original_fare_usd VIVTOT sVPH_AUTOM sVPH_CEL sVPH_INTER year user GRAPROES cash

rename original_fare_usd fares
reshape wide fares, i(year user VIVTOT GRAPROES sVPH_AUTOM sVPH_CEL sVPH_INTER) j(cash)

replace fares0=0 if fares0==.
replace fares1=0 if fares1==.

gen time=1 if year==2016
replace time=2 if year>2016

collapse (sum) fares* (mean) VIVTOT GRAPROES sVPH_AUTOM sVPH_CEL sVPH_INTER , by(user time)
bysort user: gen N=_N
keep if N==2
drop N

gen type="pure credit" if fares0>0 & fares1==0
replace type="pure cash" if fares0==0 & fares1>0
replace type="mixed" if fares0>0 & fares1>0

keep if time==2

gen switcher=(type=="mixed" | type=="pure cash")

		binscatter switcher GRAPROES if GRAPROES>5 & GRAPROES<16, ///
		nq(100) linetype(none) lcolor(navy) mcolor(ebblue) xtitle(Average years of schooling) ///
		ytitle(Share of users)savegraph("$dirout/FigureC4a.eps") replace  

		binscatter switcher sVPH_INTER [w=VIVTOT], ///
		nq(100) linetype(none) lcolor(navy) mcolor(ebblue) ///
		xtitle("Share of homes with internet") ///
		ytitle(Share of users) savegraph("$dirout/FigureC4b.eps") replace
		
		binscatter switcher sVPH_CEL [w=VIVTOT], ///
		nq(100) linetype(none) lcolor(navy) mcolor(ebblue) ///
		xtitle("Share of homes with cell phone") ///
		ytitle(Share of users) savegraph("$dirout/FigureC4c.eps") replace
		
		binscatter switcher sVPH_AUTOM [w=VIVTOT], ///
		nq(100) linetype(none) lcolor(navy) mcolor(ebblue) ///
		xtitle("Share of homes with car") ///
		ytitle(Share of users) savegraph("$dirout/FigureC4d.eps") replace
		
		

		

		
